package com.steven.download.download.db.room;

import android.content.Context;

import com.steven.download.download.db.DownloadEntity;
import com.steven.download.entity.JsonPathEntity;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.DatabaseConfiguration;
import androidx.room.InvalidationTracker;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteOpenHelper;

/**
 * @Des:
 * @Author: hwz
 * @Date:2021/11/10 0010
 * @Version: 1.0
 */
@Database(entities = {DownloadEntity.class, JsonPathEntity.class}, version = AppDataBase.DB_VERSION)
public abstract class AppDataBase extends RoomDatabase {

    /**  数据库 */
    public static final int DB_VERSION = 1;


    private static final Object sLock = new Object();

    private static final String DB_NAME = "download_app";

    private static AppDataBase INSTANCE;

    private static String DB_FILE_NAME = DB_NAME + ".db";

    public static AppDataBase getInstance(Context context) {

        synchronized (sLock) {
            if (INSTANCE == null) {
                INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                        AppDataBase.class, DB_FILE_NAME)
                        .allowMainThreadQueries()
//                        .fallbackToDestructiveMigration()//如果更新版本，没有加入迁移，则会删除所有数据
                        .build();
            }
            return INSTANCE;
        }
    }

    public abstract DownloadDao getDownloadDao();

    public abstract UninstallDao getUninstallDao();

}
